﻿using System;
using NUnit.Framework;
using OpenQA.Selenium;

namespace mvcForum.Tests.WebUI {

	[TestFixture]
	public class L099_StatusChangeTests {
		private static IWebDriver driver;
		private String forumName;
		private const Int32 indexDelay = 15;

		#region Initialization and cleanup
		[TestFixtureSetUp]
		public void TestInitialize() {
			driver = TestHelper.GetDriver();

			// Log on as administrator!
			driver.LogOn(Constants.Users.Admin.Email, Constants.Users.Admin.Password);

			forumName = Guid.NewGuid().ToString();
			driver.CreateForum("Test board", "Category 1", forumName, "", 1);
			driver.SetStandardAccess("Test board", "Category 1", forumName);

			// Disable multi-post anti-spam!
			driver.DisableAntiSpam();

			driver.EnableLucene(false, indexDelay);

			driver.LogOff();
		}

		[TestFixtureTearDown]
		public void TestCleanup() {
			if (driver != null) {
				driver.Close();
			}
		}
		#endregion

		[Test]
		public void SearchStatusChange() {
			driver.LogOn(Constants.Users.Regular.Email, Constants.Users.Regular.Password);

			String searchPhrase = "phoenix";
			String topicTitle = "A very special topic!";
			driver.CreateTopic(forumName, topicTitle, "We need to find out if this is found with search, and then when put in quarantine or deleted, not found anymore! And when visible again, found again! The secret search phrase is: " + searchPhrase);

			driver.Wait(indexDelay * 2);

			driver.Search(searchPhrase, forumName);

			// Let's see the result!!
			Assert.AreEqual(1, driver.FindElements(By.ClassName("topictitle")).Count, "The search word was not found anywhere, should have given us a hit on the title!");

			driver.QuarantineTopic(forumName, topicTitle);

			driver.Wait(indexDelay * 2);

			driver.Search(searchPhrase, forumName);

			// Let's see the result!!
			Assert.AreEqual(0, driver.FindElements(By.ClassName("topictitle")).Count, "The search word was found, it should be in quarantine!");

			driver.UnquarantineTopic(forumName, topicTitle);

			driver.Wait(indexDelay * 2);

			driver.Search(searchPhrase, forumName);

			// Let's see the result!!
			Assert.AreEqual(1, driver.FindElements(By.ClassName("topictitle")).Count, "The search word was not found anywhere, should have given us a hit on the title!");
		}
	}
}